import 'package:flutter/material.dart';

class PromotionPage extends StatelessWidget {
  const PromotionPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xFFF7F7F7),
      appBar: AppBar(
        title: const Text(
          '优惠活动',
          style: TextStyle(
            fontWeight: FontWeight.w600,
            color: Colors.white,
          ),
        ),
        centerTitle: true,
        backgroundColor: Theme.of(context).colorScheme.primary,
        leading: IconButton(
          icon: const Icon(Icons.arrow_back, color: Colors.white),
          onPressed: () => Navigator.of(context).pop(),
        ),
      ),
      body: ListView.builder(
        padding: const EdgeInsets.all(15),
        itemCount: _getPromotions().length,
        itemBuilder: (context, index) {
          final promotion = _getPromotions()[index];
          return _buildPromotionItem(promotion);
        },
      ),
    );
  }

  Widget _buildPromotionItem(PromotionItem promotion) {
    return Container(
      margin: const EdgeInsets.only(bottom: 15),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(12),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.05),
            blurRadius: 5,
            offset: const Offset(0, 2),
          ),
        ],
      ),
      child: Column(
        children: [
          // 活动图片
          ClipRRect(
            borderRadius: const BorderRadius.vertical(top: Radius.circular(12)),
            child: Image.network(
              promotion.imageUrl,
              height: 160,
              width: double.infinity,
              fit: BoxFit.cover,
              // 添加占位图
              errorBuilder: (context, error, stackTrace) {
                return Container(
                  height: 160,
                  color: Colors.grey[200],
                  child: Icon(
                    Icons.image_not_supported,
                    size: 50,
                    color: Colors.grey[400],
                  ),
                );
              },
            ),
          ),
          // 活动内容
          Padding(
            padding: const EdgeInsets.all(15),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  children: [
                    Container(
                      padding: const EdgeInsets.symmetric(
                        horizontal: 8,
                        vertical: 3,
                      ),
                      decoration: BoxDecoration(
                        color: promotion.tagColor.withOpacity(0.1),
                        borderRadius: BorderRadius.circular(4),
                      ),
                      child: Text(
                        promotion.tag,
                        style: TextStyle(
                          color: promotion.tagColor,
                          fontSize: 12,
                        ),
                      ),
                    ),
                    const Spacer(),
                    Text(
                      promotion.date,
                      style: TextStyle(
                        color: Colors.grey[500],
                        fontSize: 12,
                      ),
                    ),
                  ],
                ),
                const SizedBox(height: 10),
                Text(
                  promotion.title,
                  style: const TextStyle(
                    fontSize: 16,
                    fontWeight: FontWeight.w600,
                  ),
                ),
                const SizedBox(height: 6),
                Text(
                  promotion.description,
                  style: TextStyle(
                    fontSize: 14,
                    color: Colors.grey[600],
                    height: 1.5,
                  ),
                ),
                const SizedBox(height: 12),
                Row(
                  children: [
                    Expanded(
                      child: OutlinedButton(
                        onPressed: () {
                          // 处理查看详情
                        },
                        style: OutlinedButton.styleFrom(
                          foregroundColor: Colors.blue,
                          side: const BorderSide(color: Colors.blue),
                          padding: const EdgeInsets.symmetric(vertical: 8),
                        ),
                        child: const Text('查看详情'),
                      ),
                    ),
                    const SizedBox(width: 12),
                    Expanded(
                      child: FilledButton(
                        onPressed: () {
                          // 处理立即参与
                        },
                        style: FilledButton.styleFrom(
                          backgroundColor: Colors.blue,
                          padding: const EdgeInsets.symmetric(vertical: 8),
                        ),
                        child: const Text('立即参与'),
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  List<PromotionItem> _getPromotions() {
    return [
      PromotionItem(
        title: '新人专享优惠',
        description: '新用户首单立减50元，大件搬运、家具拆装等服务均可使用，最高优惠100元。',
        date: '2024.01.01-2024.12.31',
        tag: '新人专享',
        tagColor: Colors.orange,
        imageUrl: 'https://picsum.photos/800/400?random=1',
      ),
      PromotionItem(
        title: '周末特惠',
        description: '周末期间下单享受8折优惠，提前3天预约可享受额外5%优惠。',
        date: '每周六日',
        tag: '限时优惠',
        tagColor: Colors.green,
        imageUrl: 'https://picsum.photos/800/400?random=2',
      ),
      PromotionItem(
        title: '邀请好友返现',
        description: '邀请好友注册并完成首单，双方均可获得50元现金奖励。',
        date: '长期有效',
        tag: '活动推广',
        tagColor: Colors.purple,
        imageUrl: 'https://picsum.photos/800/400?random=3',
      ),
    ];
  }
}

class PromotionItem {
  final String title;
  final String description;
  final String date;
  final String tag;
  final Color tagColor;
  final String imageUrl;

  PromotionItem({
    required this.title,
    required this.description,
    required this.date,
    required this.tag,
    required this.tagColor,
    required this.imageUrl,
  });
} 